<template>
  <div class="position-detail-container">
    <!-- 顶部盒子 -->
    <div class="top-box">
      <van-sticky>
        <!-- 顶部导航 -->
        <van-nav-bar :border="false" @click-left="$router.go(-1)">
          <template #left>
            <i class="iconfont iconbtn_nav_back"></i>
          </template>
          <template #right>
            <i @click="collect" class="iconfont iconbtn_shoucang_nor"></i>
            <i @click="showShare = true" class="iconfont iconbtn_share"></i>
          </template>
        </van-nav-bar>
      </van-sticky>
      <!-- 信息 -->
      <h2>
        {{ detail.name }} <span class="score">{{ detail.salary }}</span>
      </h2>
      <!-- 职位 -->
      <div class="job-tags">
        <span> <i class="iconfont iconicon_city"></i>{{ detail.city }}</span>
        <span>
          <i class="iconfont iconicon_nian"></i>{{ detail.experience }}</span
        >
        <span>
          <i class="iconfont iconicon_xueli"></i>{{ detail.education }}</span
        >
      </div>
      <!-- 工作时间 -->
      <div class="time-tags">
        {{ detail.feature && detail.feature.join('·') }}
      </div>
    </div>

    <!-- 内容盒子 -->
    <div class="main-box van-hairline--bottom">
      <h3>职位描述</h3>
      <div class="responsibility-box" v-html="detail.responsibility"></div>
      <!-- 公司盒子 -->
      <div
        class="company-box van-hairline--top"
        @click="$router.push('/companyDetail/' + detail.company.id)"
      >
        <div class="logo-wrap van-hairline--surround">
          <img :src="detail.company.logo" alt="" />
        </div>

        <div class="info-box">
          <div class="title">{{ detail.company.name }}</div>
          <div class="tags">
            <span>{{ detail.company.type }}</span>
            <span>{{ detail.company.step }}</span>
            <span>{{ detail.company.scale }}</span>
          </div>
        </div>
        <i class="iconfont iconicon_more"></i>
      </div>
    </div>
    <!-- 底部盒子 -->
    <div class="bottom-box">
      <van-button type="danger" @click="toInterView">去刷题</van-button>
    </div>
    <!-- 分享界面 -->
    <van-share-sheet
      v-model="showShare"
      title="立即分享给好友"
      :options="options"
      @select="onSelect"
    />
  </div>
</template>

<script>
import { positionDetail } from '../../api/api'
import { mapMutations } from 'vuex'
export default {
  data () {
    return {
      // 职位详情
      detail: {
        company: {}
      },
      showShare: false,
      options: [
        { name: '微信', icon: 'wechat' },
        { name: '微博', icon: 'weibo' },
        { name: '复制链接', icon: 'link' },
        { name: '分享海报', icon: 'poster' },
        { name: '二维码', icon: 'qrcode' }
      ]
    }
  },
  methods: {
    ...mapMutations(['SETQUESTION']),
    collect () {
      this.$toast('即将推出，敬请期待')
    },
    onSelect (op, i) {
      // console.log(op)
      // console.log(i)
      this.$toast('即将推出，敬请期待')
    },
    toInterView () {
      const questionData = this.detail.questions.map((v, i) => {
        if (i === 0) {
          return {
            id: v.id,
            detail: {
              type: +v.type,
              title: v.title,
              tag: v.tag.split(' '),
              difficulty: +v.difficulty,
              option: [v.optionA, v.optionB, v.optionC, v.optionD]
            }
          }
        } else {
          return { id: v.id }
        }
      })
      this.SETQUESTION(questionData)
      // 去刷题页
      this.$router.replace(`/interview?position=${this.detail.id}`)
    }
  },
  async created () {
    const detailRes = await positionDetail(this.$route.params.id)
    // console.log(detailRes.data)
    this.detail = detailRes.data
    // 处理logo
    this.detail.company.logo =
      process.env.VUE_APP_URL + this.detail.company.logo
  }
}
</script>

<style lang="less">
.position-detail-container {
  padding-bottom: 99px;
  .van-nav-bar {
    box-shadow: 0px 2px 4px 0px rgba(24, 26, 57, 0.04);

    .van-nav-bar__left {
      padding-left: 0;
    }
    .iconbtn_nav_back {
      font-size: 44px;
    }
    .van-nav-bar__right {
      display: flex;
      align-items: center;
    }
    .iconbtn_shoucang_nor {
      margin-right: 10px;
    }
    .iconfont {
      font-size: 30px;
    }
  }
  .top-box {
    padding: 0 0 10px;
    background: #fff;
    box-shadow: 0px 2px 4px 0px rgba(24, 26, 57, 0.04);
    h2 {
      font-size: 22px;
      font-weight: 600;
      padding: 0 15px;
      color: #222222;
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      span {
        font-size: 16px;
        font-weight: 400;
        color: #e40137;
      }
    }
    .job-tags {
      margin-top: 19px;
      display: flex;
      padding: 0 15px;
      span {
        font-size: 12px;
        margin-right: 18px;
        display: flex;
        align-items: center;
        color: #181a39;
      }
      i {
        color: #b4b4bc;
      }
    }
    .time-tags {
      margin-top: 14px;
      font-size: 12px;
      color: #b4b4bd;
      padding: 0 15px;
    }
  }
  .main-box {
    padding: 24px 15px 0;
    background-color: white;
    // box-shadow: 0px 2px 4px 0px inset rgba(24, 26, 57, 0.04);
    h3 {
      font-size: 18px;
      font-weight: 500;
      text-align: left;
      margin: 0;
      color: #181a39;
      margin-bottom: 20px;
    }
    .responsibility-box {
      font-size: 16px;
    }
    h4 {
      margin: 0;
      margin-top: 26px;
      font-size: 16px;
      font-weight: 500;
      color: #b4b4bd;
    }
    p {
      font-size: 16px;
      font-weight: 400;
      text-align: justify;
      color: #181a39;
      line-height: 27px;
    }
    .company-box {
      display: flex;
      height: 104px;
      align-items: center;
      justify-content: space-between;
      .logo-wrap {
        width: 58px;
        height: 58px;
        margin-right: 11px;
        img {
          display: block;
          width: 100%;
          height: 100%;
        }
      }
      .info-box {
        .title {
          font-size: 14px;
          font-weight: 400;
          color: #181a39;
        }
        .tags {
          margin-top: 11px;
          font-size: 12px;
          font-weight: 400;
          color: #545671;
          span {
            height: 18px;
            border: 1px solid #b4b4bd;
            border-radius: 3px;
            margin-right: 7px;
            padding: 0 7px;
            color: #545671;
          }
        }
      }
      .icon-font {
        font-size: 10px;
      }
    }
  }
  .bottom-box {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 99px;
    padding: 15px;
    padding-bottom: 0;
    background: #fcfcfc;
    .van-button {
      width: 100%;
      border-radius: 8px;
    }
  }
}
</style>
